package com.Sdebruijn.curriculumvitae;

import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.Sdebruijn.curriculumvitae.asynctask.LoadHobbyDataAsyncTask;
import com.Sdebruijn.curriculumvitae.listeners.OnDoneLoadingListener;

public class HobbyActivity extends BaseActivity implements OnDoneLoadingListener {
	private LoadHobbyDataAsyncTask mLoadHobbyDataAsyncTask;

	private ImageView iv_hobby_block_logo;

	private AnimationDrawable anim_welder;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_hobby);
		getSupportActionBar().setTitle("Hobbies");
		getSupportActionBar().setLogo(R.drawable.icon_thumbs_up);

		RelativeLayout rl_hobbies_data = (RelativeLayout) findViewById(R.id.rl_hobbies_data);

		mLoadHobbyDataAsyncTask = new LoadHobbyDataAsyncTask(rl_hobbies_data, this, this);
		mLoadHobbyDataAsyncTask.execute();

	}

	@Override
	public void onDoneLoading(View view) {
		LinearLayout ll_apps_data = (LinearLayout) view;
		// TODO Seems pretty hacky : update this later into a cleaner way.
		for (int i = 0; i < ll_apps_data.getChildCount(); i++) {
			LinearLayout child = (LinearLayout) ll_apps_data.getChildAt(i);
			// The LinearLayout which holds the whole visible block is always
			// child(0)
			View innerChild = child.getChildAt(0);

			iv_hobby_block_logo = (ImageView) innerChild.findViewById(R.id.iv_hobby_block_logo);

			// Get the background, which has been compiled to an
			// AnimationDrawable
			// object.
			anim_welder = (AnimationDrawable) iv_hobby_block_logo.getBackground();
			// Start the animation (looped playback by default).
			anim_welder.start();
		}
	}

}
